#!/usr/bin/ruby -w

class Cake
  attr_reader(:side_one, :side_two)

  def initialize(slice)
    if slice > 0.9 || slice < 0.1
      raise ArgumentError.new("Slice may not be bigger than 0.9 or smaller than 0.1")
    end
		
    @side_one = slice
    @side_two = 1.0 - slice
  end

  def biggest
    return [@side_one, @side_two].max
  end

  def smallest
    return [@side_one, @side_two].min
  end
end

class Joe
  def cut_first_cake
    return Cake.new(0.7, 0.3)
  end

  def cut_second_cake(first_cake, first_cake_chosen)
    if first_cake_chosen == true && first_cake.biggest() >= 0.5
      return Cake.new(0.9)
    else
      return Cake.new(0.5)
    end
  end

  def my_cake_amount(first_cake, second_cake, jills_choice)
    if jills_choice == true
      return first_cake.smallest() + second_cake.biggest()
    else
      return first_cake.biggest() + second_cake.smallest()
    end
  end
end

class Jill
  def pick_cake?(first_cake)
    return first_cake.biggest >= 0.7
  end
end

if __FILE__ == $PROGRAM_NAME
  if ARGV.length != 3
    abort("Usage: ./cake.rb")
  end
end
